package com.hzvtc.bosswang.manageeducation.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzvtc.bosswang.manageeducation.domain.UserCourse;
import com.hzvtc.bosswang.manageeducation.mapper.UserCourseMapper;
import com.hzvtc.bosswang.manageeducation.service.UserCourseService;
import com.hzvtc.bosswang.manageservice.api.UserApi;
import com.hzvtc.bosswang.manageservice.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class UserCourseServiceImpl implements UserCourseService {

    @Resource
    private UserCourseMapper userCourseMapper;

    @Resource
    private UserApi userApi;


    @Override
    public ArrayList<User> selectStudentsByCourseId(Long id) {
        ArrayList<User> selectedUsers=new ArrayList<>();
        List<Long> users = userCourseMapper.selectStudentsByCourseId(id);
        users.forEach(userId->{
            User user=userApi.getUserInfoById(userId);
            System.out.println(userId);
            System.out.println(user);
            if (user!=null){
                selectedUsers.add(user);
            }
        });
        return selectedUsers;
    }

    @Override
    public Integer addUserCourse(UserCourse userCourse) {
        return userCourseMapper.add(userCourse);
    }

    @Override
    public Integer editUserCourse(UserCourse userCourse) {
        return userCourseMapper.edit(userCourse);
    }

    @Override
    public Integer deleteUserCourse(Long id) {
        return userCourseMapper.delete(id);
    }

    @Override
    public UserCourse selectUserCourseById(Long id) {
        return userCourseMapper.selectUserCourseById(id);
    }

    @Override
    public Page<UserCourse> listUserCourse(Page<UserCourse> page, UserCourse userCourse) {
        return userCourseMapper.selectUserCourseList(page,userCourse);
    }
}
